// pages/serviceEval/serviceEval.js
const app =getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    fanglist:[
      {id:1,orderid:32489565655656,sumper:45,tel:14578651245,state:1,tag:1,address:'广州市番禺区石岗路地址地址地址地址地址',user:'刘德华',active:3,time:'2020/09/06'},
    ],
    value: 0,
    status:3,
    checkboxArr: [
      {
       checked: false,//是否选中
       id: "1",//部门能id
       name: "自定义",
      },
      {checked: false,id: "2",name: "服务有礼",},
      // {checked: false,id: "2",name: "服务有礼",},
      // {checked: false,id: "2",name: "服务有礼",},
      {checked: false,id: "3",name: "专业讲师",},
      {checked: false,id: "5",name: "最佳指导",}
     ],
     hiddenmodalput:true,
     customize:'',
     textArea:'',//输入信息
     submitbtn:true,//提交评价显示
     ordertype:0,
     select: [{
      name: '服务有礼',
      index: 0
    }, {
      name: '专业讲师',
      index: 0
    }, {
      name: '最佳指导',
      index: 0
    }],
    Model:false,
  },
  getUserInfo(event) {
    var that = this;
    var select = that.data.select;
    select.push({name:that.data.customize,index:0});
    this.setData({ Model: false ,select:select, getUserInfo(event) {
            var that = this;
            var select = that.data.select;
            select.push({name:that.data.customize,index:0});
            this.setData({ Model: false ,select:select});
          },
        
          onClose() {
            this.setData({ Model: false });
          },});
  },

  onClose() {
    this.setData({ Model: false });
  },
  choose(e) {
    var that = this;
    var index = e.currentTarget.dataset.index;
    console.log(index)
    var select = this.data.select;
    if (select[index].index != 1) {
      select[index].index = 1
    } else {
      select[index].index = 0
    }
    that.setData({
      select: select
    })
    console.log(select)
  },
  customize(e) {
    var that = this;
    that.setData({
      customize:e.detail.value
    })
  },
  showModel(e) {
    var that = this;
    that.setData({
      Model:true,
      customize:''
    })
      },
  //标签多选
  // checkbox: function (e) {
  //   var index = e.currentTarget.dataset.index;//获取当前点击的下标
  //   var checkboxArr = this.data.checkboxArr;//选项集合
  //   checkboxArr[index].checked = !checkboxArr[index].checked;//改变当前选中的checked值
  //   this.setData({
  //    checkboxArr: checkboxArr
  //   });
  //  },
  onChange(event) {this.setData({value: event.detail,});},
  //点击弹出
	modalinput(){
		this.setData({hiddenmodalput: !this.data.hiddenmodalput})
	},
  //取消按钮
  cancel: function(){this.setData({hiddenmodalput: true});},
  //确认
  confirm: function(){this.setData({hiddenmodalput: true})},
  //文字评论
  bindTextAreaBlur: function(e) { this.setData({ textArea : e.detail.value })},
  submit(e){
    var i = e.currentTarget.dataset.status;
    let that = this;
    let rate = that.data.value;
    let texteare = that.data.textArea;
    var i = e.currentTarget.dataset.status;//订单状态
    var type = Number(that.data.ordertype);//订单状态
    let json = { pk : that.data.fanglist.id}
    let data = {
      rate: rate,
      comment: texteare
    }
    if(!data.rate&&!data.comment){
      wx.showToast({
        title: '你没有填写评价哦',
        icon: 'none',
        duration: 1500
      })
      return false //阻止发起请求
    }
    // console.log(datalist)
    if(type==1){
      app.ports.api57({json,data}).then((res)=>{
        // console.log(res)
        wx.showToast({
          title: '评价成功',
          icon: 'success',
          duration: 1500
        })
      }).catch(()=>{console.error('评价失败！')})
    }else if(type == 2){
      app.ports.api58({json,data}).then((res)=>{
        // console.log(res)
        wx.showToast({
          title: '评价成功',
          icon: 'success',
          duration: 1500
        })
      }).catch(()=>{console.error('评价失败！')})
    }else if(type == 3){
      app.ports.api59({json,data}).then((res)=>{
        // console.log(res)
        wx.showToast({
          title: '评价成功',
          icon: 'success',
          duration: 1500
        })
      }).catch(()=>{console.error('评价失败！')})
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    let typeId = options.type;
    this.setData({ ordertype : typeId})
    var data  = {pk:options.id}
    switch(typeId){
      case '1'://优选
      getApp().ports.api44({data}).then((res) => {
        var that = this;
        console.log(res.data)
        let dataList = res.data; //获取到数据
        if(dataList.rate&&dataList.comment){
          that.setData({ submitbtn : false})
          that.setData({ value : dataList.rate });//获取评论数据
          that.setData({ texteare : dataList.comment });
        }
        if(res.data.marketer){
          let data = { user_pk : res.data.marketer }
          getApp().ports.api56({data}).then((res)=>{
            // console.log(res.data)
            dataList.name = res.data.nickname;
            dataList.telphone = res.data.phone;
            that.setData({ fanglist: dataList })
          }).catch(()=>{console.error('获取用户信息失败！')})
        }
        dataList.arr = options.time.substring(5,16).split("T");
        if(dataList.marketer_join_time) dataList.arr1 = dataList.marketer_join_time.split(" ");
        if(dataList.auction_before_time) dataList.arr2 = dataList.auction_before_time.split(" ");
        if(dataList.auctioning_time) dataList.arr3 = dataList.auctioning_time.split(" ");
        if(dataList.auction_deal_time) dataList.arr4 = dataList.auction_deal_time.split(" ");
        if(dataList.auction_after_time) dataList.arr5 = dataList.auction_after_time.split(" ");
        if(dataList.service_finish_time) dataList.arr6 = dataList.service_finish_time.split(" ");
        if(dataList.defeat_time) dataList.arr7 = dataList.defeat_time.split(" "); //失败时间
        dataList.time = options.time.substring(0,10);
        dataList.type = options.type;
        that.setData({ fanglist: dataList })
      }).catch((error) => {
        console.error(error);
      });  
      break;
      case '2'://折扣
        getApp().ports.api88({data}).then((res) => {
          var that = this;
          console.log(res.data)
          let dataList = res.data; //获取到数据
          if(dataList.rate&&dataList.comment){
            that.setData({ submitbtn : false})
            that.setData({ value : dataList.rate });//获取评论数据
            that.setData({ texteare : dataList.comment });
          }
          if(res.data.marketer){
            let data = { user_pk : res.data.marketer }
            getApp().ports.api56({data}).then((res)=>{
              // console.log(res.data)
              dataList.name = res.data.nickname;
              dataList.telphone = res.data.phone;
              that.setData({ fanglist: dataList })
            }).catch(()=>{console.error('获取用户信息失败！')})
          }
          dataList.arr = options.time.substring(5,16).split("T");
          if(dataList.marketer_join_time) dataList.arr1 = dataList.marketer_join_time.split(" ");
          if(dataList.auction_before_time) dataList.arr2 = dataList.auction_before_time.split(" ");
          if(dataList.auctioning_time) dataList.arr3 = dataList.auctioning_time.split(" ");
          if(dataList.auction_deal_time) dataList.arr4 = dataList.auction_deal_time.split(" ");
          if(dataList.auction_after_time) dataList.arr5 = dataList.auction_after_time.split(" ");
          if(dataList.service_finish_time) dataList.arr6 = dataList.service_finish_time.split(" ");
          if(dataList.defeat_time) dataList.arr7 = dataList.defeat_time.split(" "); //失败时间
          dataList.time = options.time.substring(0,10);
          dataList.type = options.type;
          that.setData({ fanglist: dataList })
          // this.setData({ fanglist : res })
        }).catch((error) => {
          console.error(error);
        });  
      break;
      case '3'://放盘
        getApp().ports.api111({data}).then((res) => {
          var that = this;
          console.log(res.data)
          let dataList = res.data; //获取到数据
          if(dataList.rate&&dataList.comment){
            that.setData({ submitbtn : false})
            that.setData({ value : dataList.rate });//获取评论数据
            that.setData({ texteare : dataList.comment });
          }
          if(res.data.marketer){
            let data = { user_pk : res.data.marketer }
            getApp().ports.api56({data}).then((res)=>{
              // console.log(res.data)
              dataList.name = res.data.nickname;
              dataList.telphone = res.data.phone;
              that.setData({ fanglist: dataList })
            }).catch(()=>{console.error('获取用户信息失败！')})
          }
          dataList.arr = options.time.substring(5,16).split("T");
          if(dataList.marketer_join_time) dataList.arr1 = dataList.marketer_join_time.substring(5,16).split("T");
          if(dataList.auction_before_time) dataList.arr2 = dataList.auction_before_time.substring(5,16).split("T");
          if(dataList.auctioning_time) dataList.arr3 = dataList.auctioning_time.substring(5,16).split("T");
          if(dataList.auction_deal_time) dataList.arr4 = dataList.auction_deal_time.substring(5,16).split("T");
          if(dataList.auction_after_time) dataList.arr5 = dataList.auction_after_time.substring(5,16).split("T");
          if(dataList.service_finish_time) dataList.arr6 = dataList.service_finish_time.substring(5,16).split("T");
          if(dataList.defeat_time) dataList.arr7 = dataList.defeat_time.substring(5,16).split("T"); //失败时间
          dataList.time = options.time.substring(0,10);
          dataList.type = options.type;
          that.setData({ fanglist: dataList })
        }).catch((error) => {
          console.error(error);
        });  
      break;
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  
})